//
//  TTS.m
//  SBChinese
//
//  Created by Luo Sheng on 10/14/09.
//  Copyright 2009 Eike Consulting, LLC. All rights reserved.
//

#import "TTS.h"


@implementation TTS

static NSString *sDict = nil;

+ (NSString *)dict {
	if (sDict == nil) {
		NSString *dictPath = [[NSBundle mainBundle] pathForResource:@"dict" ofType:@"txt"];
		sDict = [NSString stringWithContentsOfFile:dictPath encoding:NSUTF8StringEncoding error:nil];
	}
	return sDict;
}

+ (NSString *)pinyinFor:(NSString *)character {
	
	NSString *s = [TTS dict];
	
	NSRange startRange = [s rangeOfString:character];
	startRange.length = [s length] - startRange.location;
	
	NSRange a1 = [s rangeOfString:@"[" options:NSCaseInsensitiveSearch range:startRange];
	NSRange a2 = [s rangeOfString:@"]" options:NSCaseInsensitiveSearch range:startRange];
	NSRange r;
	r.location = a1.location + 1;
	r.length = a2.location - a1.location - 1;
	a1.length = a2.location - a1.location;
	
	return [s substringWithRange:r];
}

@end
